package com.tinxing.bp.config;


import com.baomidou.dynamic.datasource.toolkit.StringUtils;
import com.p6spy.engine.spy.appender.MessageFormattingStrategy;
import com.tinxing.bp.commons.utils.SQLFormatter;
import com.tinxing.bp.commons.utils.ToolUtil;

/**
 * @description: SQL分析打印工具(不能用于生产环境)
 * @author: yangxianghua
 * @create: 2020-12-14 09:03
 **/
public class P6SpyConfig implements MessageFormattingStrategy {
    @Override
    public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) {
        String sqlFormat = new SQLFormatter().format(sql);
        return ToolUtil.isNotEmpty(sql) ? " 执行SQL消耗时间：" +
                elapsed + " 毫秒 " + "执行时间: " + now + "\n 执行的 SQL 语句：" +
                sqlFormat + "\n" : "";
    }
}
